home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Utilities / AmiMirror / Developer / prefs / source / SomeOther.h < prev    next >
Encoding:
Text File  |  1999-06-30  |  11.2 KB  |  301 lines

  1.  
  2. ///¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ <
  3. ///
  4. ///                           Some stupid routines :)                         <
  5. ///
  6. ///¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ <
  7. ///
  8. /*                         ­¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¯
  9. ­¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¥    IntuiRefresh()   ª¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¯
  10. ¢                          ¿¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡´                          ¢
  11. ¢ See for moving reqtools requestrers and refresh program windows which are ¢
  12. ¢                              trashed by ones.                             ¢
  13. ¿¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡´
  14. */
  15. void __saveds __asm IntuiRefresh (REG(a0) struct Hook *hook, REG(a2) struct rtReqInfo *reqinfo, REG(a1) struct IntuiMessage *imsg)
  16. {
  17.   if (imsg->Class == IDCMP_REFRESHWINDOW)
  18.     DoMethod (AmiMirrorPrefs, MUIM_Application_CheckRefresh);
  19. }
  20. ///¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ <
  21. ///
  22. ULONG __stdargs DoSuperNew (struct IClass *cl, Object *obj, ULONG tag1,...)
  23. {
  24.   return (DoSuperMethod (cl, obj, OM_NEW, &tag1, NULL));
  25. }
  26. ///¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ <
  27. ///
  28. // get atribute of an object
  29.  
  30. LONG xget (Object *obj, ULONG attribute)
  31. {
  32.   LONG x;
  33.   get (obj, attribute, &x);
  34.   return (x);
  35. }
  36. ///¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡ <
  37. ///
  38. // get string pointer of an string object
  39.  
  40. STRPTR getstr (Object *obj)
  41. {
  42.   return ((STRPTR)xget (obj,MUIA_String_Contents));
  43. }
  44. //--------------------------------------------------------------------
  45. // Make program's message with EasyRequest() or MUI_Request()
  46.  
  47. LONG MakeRequest (ULONG title, ULONG text, ULONG buttons, APTR arg1, ...)
  48. {
  49.   UBYTE txt_buf[MSG_MAXSIZE];
  50.  
  51.   struct EasyStruct es = { sizeof(struct EasyStruct), 0L, NULL, NULL, NULL };
  52.  
  53.   if (AmiMirrorPrefs)
  54.     {
  55.       RDF (txt_buf, MUI_TEXTCENTER_FMT, (ULONG)GETMES(text));
  56.       return (MUI_RequestA (AmiMirrorPrefs, MainWin, 0, GETMES(title), GETMES(buttons), txt_buf,  &arg1));
  57.     }
  58.   es.es_Title        = GETMES(title);
  59.   es.es_TextFormat   = GETMES(text);
  60.   es.es_GadgetFormat = GETMES(buttons);
  61.   DisplayBeep (NULL);
  62.   return (EasyRequestArgs (NULL, &es, NULL, &arg1));
  63. }
  64. //--------------------------------------------------------------------
  65. // Translate DOS-error code into descriptor string
  66.  
  67. STRPTR FaultStr (LONG error)
  68. {
  69.   Fault (error, GETMES(DOS_ERROR_STR), dosfault, 2*FAULT_MAX);
  70.   return (dosfault);
  71. }
  72. //--------------------------------------------------------------------
  73. // Convert array of ULONGs into array of STRPTRs
  74.  
  75. void FillIt (VAGUE *array1, ...)
  76. {
  77.   ULONG count;
  78.   VAGUE *a;
  79.   VAGUE **pa = &array1;
  80.  
  81.   while (a = *pa++)
  82.     {
  83.       for (count = 0L; a[count].num; count++)
  84.         a[count].str = GETMES(a[count].num);
  85.     }
  86. }
  87. //--------------------------------------------------------------------
  88. // Build list of XPK packers
  89.  
  90. BOOL GetXpkList (void)
  91. {
  92.   if (! XL)
  93.     XL = (struct XpkPackerList *) XpkAllocObject (XPKOBJ_PACKERLIST, 0);
  94.   if (XL)
  95.     {
  96.       if (! (XpkQueryTags (XPK_PackersQuery, XL, XPK_Preferences, FALSE, TAG_DONE)))
  97.         return (TRUE);
  98.     }
  99.   MakeRequest (REQ_TITLE_ERROR, XPK_NOLIST_ERROR, CANCEL_BUT, NULL);
  100.   return (FALSE);
  101. }
  102.  
  103. //--------------------------------------------------------------------
  104. // Get information about packer
  105.  
  106. BOOL GetXpkInfo (STRPTR method)
  107. {
  108.   if (method)
  109.     {
  110.       if (! XI)
  111.         XI = (struct XpkPackerInfo *) XpkAllocObject (XPKOBJ_PACKERINFO, 0);
  112.       if (XI)
  113.         {
  114.           if (! (XpkQueryTags (XPK_PackerQuery, XI, XPK_PackMethod, method, TAG_DONE)))
  115.             return (TRUE);
  116.         }
  117.       MakeRequest (REQ_TITLE_ERROR, XPK_NOINFO_ERROR, CANCEL_BUT, method);
  118.     }
  119.   return (FALSE);
  120. }
  121. //--------------------------------------------------------------------
  122. // - Get additional information about packer
  123.  
  124. BOOL GetXpkMode (STRPTR method, ULONG mode)
  125. {
  126.   if (method)
  127.     {
  128.       if (! XM)
  129.         XM = (struct XpkMode *) XpkAllocObject (XPKOBJ_MODE, 0);
  130.       if (XM)
  131.         {
  132.           if (! (XpkQueryTags (XPK_ModeQuery, XM,
  133.                                XPK_PackMethod, method,
  134.                                XPK_PackMode, mode, TAG_DONE)))
  135.             return (TRUE);
  136.         }
  137.       MakeRequest (REQ_TITLE_ERROR, XPK_NOINFO_ERROR, CANCEL_BUT, method);
  138.     }
  139.   return (FALSE);
  140. }
  141. //--------------------------------------------------------------------
  142. // Realise the memory allocated for the patterns' list
  143.  
  144. void FreePatList (struct List *list)
  145. {
  146.   struct Node *node;
  147.  
  148.   while (node = RemTail (list))
  149.     FreeVec (node);
  150.   FreeVec (list);
  151. }
  152. //--------------------------------------------------------------------
  153. // Load settings (patterns' list)
  154.  
  155. BOOL LoadSets (STRPTR filename, struct List *list)
  156. {
  157.   struct PatternNode  *PN;
  158.   struct SetsHeader    SH;
  159.   struct PatternHeader PH;
  160.   BPTR SetsFH;
  161.   BOOL convert = FALSE, result = GAME_OVER;
  162.  
  163.   if (SetsFH = Open (filename, MODE_OLDFILE))
  164.     {
  165.       if (Read (SetsFH, &SH, sizeof(struct SetsHeader)) == sizeof(struct SetsHeader))
  166.         {
  167.           if (SH.sh_ID == SETS_ID)
  168.             {
  169.               if (SH.sh_version <= SETS_VERSION)
  170.                 {
  171.                   if (SH.sh_version < SETS_VERSION)
  172.                     convert = TRUE;
  173.                   if (SH.sh_amount > 0L)
  174.                     {
  175.                       result = ALL_RIGHT;
  176.                       while (SH.sh_amount--)
  177.                         {
  178.                           if (PN = AllocVec (sizeof(struct PatternNode), MEMF_PUBLIC | MEMF_CLEAR))
  179.                             {
  180.                               if ((Read (SetsFH, &PH, sizeof(struct PatternHeader))   != sizeof(struct PatternHeader)) ||
  181.                                   (Read (SetsFH, PN->pn_Pattern,  PH.ph_PatternSize)  != PH.ph_PatternSize) ||
  182.                                   (Read (SetsFH, PN->pn_Storage,  PH.ph_StorageSize)  != PH.ph_StorageSize) ||
  183.                                   (Read (SetsFH, PN->pn_Password, PH.ph_PasswordSize) != PH.ph_PasswordSize))
  184.                                 {
  185.                                   FreeVec (PN);
  186.                                   if (MakeRequest (REQ_TITLE_ERROR, CANT_READ_SETS, CANCEL_CONTINUE_BUT, filename, FaultStr (IoErr())))
  187.                                     result = GAME_OVER;
  188.                                   break;
  189.                                 }
  190.                               if (convert)
  191.                                 PN->pn_Function = 0;
  192.                               else
  193.                                 PN->pn_Function = PH.ph_Function;
  194.                               PN->pn_PatternMode   = PH.ph_PatternMode;
  195.                               PN->pn_StorageMode   = PH.ph_StorageMode;
  196.                               PN->pn_StorageMethod = PH.ph_StorageMethod;
  197.                               PN->pn_PerformCheck  = PH.ph_PerformCheck;
  198.                               if (PN->pn_UseXPK = PH.ph_UseXPK)
  199.                                 {
  200.                                   strcpy (PN->pn_XPKName, PH.ph_XPKName);
  201.                                   PN->pn_XPKMode = PH.ph_XPKMode;
  202.                                 }
  203.                               PN->pn_Node.ln_Name = PN->pn_Pattern;
  204.                               AddTail (list, (struct Node *)PN);
  205.                             }
  206.                           else
  207.                             {
  208.                               MakeRequest (REQ_TITLE_ERROR, OUT_MEM, CANCEL_BUT, NULL);
  209.                               result = GAME_OVER;
  210.                               break;
  211.                             }
  212.                         }
  213.                     }
  214.                   else if (! MakeRequest (REQ_TITLE_ERROR, NOT_SETS_FILE, CANCEL_CONTINUE_BUT, filename))
  215.                     result = ALL_RIGHT;
  216.                 }
  217.               else if (! MakeRequest (REQ_TITLE_ERROR, NOT_SETS_FILE, CANCEL_CONTINUE_BUT, filename))
  218.                 result = ALL_RIGHT;
  219.             }
  220.           else if (! MakeRequest (REQ_TITLE_ERROR, NOT_SETS_FILE, CANCEL_CONTINUE_BUT, filename))
  221.             result = ALL_RIGHT;
  222.         }
  223.       else if (! MakeRequest (REQ_TITLE_ERROR, CANT_READ_SETS, CANCEL_CONTINUE_BUT, filename, FaultStr (IoErr())))
  224.         result = ALL_RIGHT;
  225.       Close (SetsFH);
  226.     }
  227.   else if (! MakeRequest (REQ_TITLE_ERROR, CANT_OPEN_SETS, CANCEL_CONTINUE_BUT, filename, FaultStr (IoErr())))
  228.     result = ALL_RIGHT;
  229.   return (result);
  230. }
  231. //--------------------------------------------------------------------
  232. // Save settings (patterns' list)
  233.  
  234. void SaveSets (STRPTR filename, Object *plist)
  235. {
  236.   struct PatternNode  *PN;
  237.   struct SetsHeader    SH;
  238.   struct PatternHeader PH;
  239.   ULONG x;
  240.   STRPTR str;
  241.   BPTR SetsFH;
  242.  
  243.   if (SH.sh_amount = xget (plist, MUIA_List_Entries))
  244.     {
  245.       SH.sh_ID = SETS_ID;
  246.       SH.sh_version = SETS_VERSION;
  247.       if (SetsFH = Open (filename, MODE_NEWFILE))
  248.         {
  249.           if (Write (SetsFH, &SH, sizeof(struct SetsHeader)) == sizeof(struct SetsHeader))
  250.             {
  251.               for (x = 0L; x < SH.sh_amount; x++)
  252.                 {
  253.                   DoMethod (plist, MUIM_List_GetEntry, x, &str);
  254.                   if (str && (PN = (struct PatternNode *)FindName (PatList, str)))
  255.                     {
  256.                       PH.ph_Function      = PN->pn_Function;
  257.                       PH.ph_PatternMode   = PN->pn_PatternMode;
  258.                       PH.ph_StorageMode   = PN->pn_StorageMode;
  259.                       PH.ph_StorageMethod = PN->pn_StorageMethod;
  260.                       PH.ph_PerformCheck  = PN->pn_PerformCheck;
  261.                       PH.ph_PatternSize   = strlen (PN->pn_Pattern);
  262.                       PH.ph_StorageSize   = strlen (PN->pn_Storage);
  263.                       if (PH.ph_UseXPK = PN->pn_UseXPK)
  264.                         {
  265.                           strcpy (PH.ph_XPKName, PN->pn_XPKName);
  266.                           PH.ph_XPKMode = PN->pn_XPKMode;
  267.                           PH.ph_PasswordSize = strlen (PN->pn_Password);
  268.                         }
  269.                       else
  270.                         {
  271.                           PH.ph_XPKName[0] = PH.ph_XPKName[1] = PH.ph_XPKName[2] =
  272.                           PH.ph_XPKName[3] = PH.ph_XPKName[4] = PH.ph_XPKName[5] = '\0';
  273.                           PH.ph_XPKMode = PH.ph_PasswordSize = 0;
  274.                         }
  275.                       if ((Write (SetsFH, &PH, sizeof(struct PatternHeader))   != sizeof(struct PatternHeader)) ||
  276.                           (Write (SetsFH, PN->pn_Pattern,  PH.ph_PatternSize)  != PH.ph_PatternSize) ||
  277.                           (Write (SetsFH, PN->pn_Storage,  PH.ph_StorageSize)  != PH.ph_StorageSize) ||
  278.                           (Write (SetsFH, PN->pn_Password, PH.ph_PasswordSize) != PH.ph_PasswordSize))
  279.                         {
  280.                           MakeRequest (REQ_TITLE_ERROR, CANT_SAVE_SETS, CANCEL_BUT, filename, FaultStr (IoErr()));
  281.                           break;
  282.                         }
  283.                     }
  284.                   else
  285.                     {
  286.                       MakeRequest (REQ_TITLE_ERROR, CANT_GIVE_SETS, CANCEL_BUT, NULL);
  287.                       break;
  288.                     }
  289.                 }
  290.             }
  291.           else
  292.             MakeRequest (REQ_TITLE_ERROR, CANT_SAVE_SETS, CANCEL_BUT, filename, FaultStr (IoErr()));
  293.           Close (SetsFH);
  294.         }
  295.       else
  296.         MakeRequest (REQ_TITLE_ERROR, CANT_OPEN_SETS, CANCEL_BUT, filename, FaultStr (IoErr()));
  297.     }
  298.   else
  299.     MakeRequest (REQ_TITLE_ERROR, LIST_EMPTY_SETS, CANCEL_BUT, NULL);
  300. }
  301.